package com.wg.db.convert;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

/**
 * @author 少爷123
 */
public class DoubleArrayConvert implements IConvert<double[]> {
    @Override
    public double[] parseObject(Object obj) {
        if (!(obj instanceof String)) {
            return new double[0];
        }

        String str = (String) obj;
        if (StrUtil.isEmpty(str)) {
            return new double[0];
        }

        String[] strings = StrUtil.splitToArray(str, ",");
        double[] array = new double[strings.length];

        for (int i = 0, len = array.length; i < len; i++) {
            array[i] = Convert.toDouble(strings[i], 0.0);
        }

        return array;
    }
}
